
//判断名称是否存在
function isNameExist(name,names){
	var flag = false;
    if(names==undefined){
     	flag = true;
    }else if(names.length==0){
			flag = true;
	}else{
		for(var i=0;i<names.length;i++){
			if (name==names[i]){
				flag = true;
				break;
			}
		}
	}
	return flag;
}

//获得节点属性值	
function getFormElementAtt(element, attname){
    var retval = "";
    if ((typeof element != "undefined") && (element != null)){
        retval = element.getAttribute(attname);
        if (retval == null)
            retval = "";
    }
    return retval;
 }

//获得节点值	
function getElementValue(tempElement){
    var value = "";
    if ((typeof tempElement != "undefined") && (tempElement != null)){
        value = tempElement.value;
		if(typeof value != "undefined"){
        	value = value.replace(/[\r\n]/g,'');
        }else{
        	return '';
        }
    }
    return value;
}

//获得表单数据	
function createFormXml(forms,names,ywid){
    var form = forms.elements;
    var size = form.length;
    var name = "";
    var formElement = null;
    var elementname = "";
    var elementvalue = "";
    var rootElement = null;
    var deltaLog = null;
    var xml = "<datas></datas>";
    var deltaLog = new ActiveXObject("Msxml2.DOMDocument.3.0");
    deltaLog.loadXML(xml);
    rootElement = deltaLog.documentElement;
    var mapElement = deltaLog.createElement("map");
    mapElement.setAttribute("key", ywid);
  
    for(var index = 0; index < size; index ++){
        formElement = form[index];
       
        //2008-12-02 LHT:过滤掉FIELDSET和legend标签
        var tagmc = formElement.tagName;        
        if((tagmc.toUpperCase()=="FIELDSET") ||(tagmc=="undefined")) continue;
        
        var comType = formElement.type.toUpperCase();
        if(comType=="BUTTON"){
        	continue;
        }
        name = getFormElementAtt(formElement, "name");
        if (isNameExist(name,names)==false){
            continue;
        }
        elementvalue = getElementValue(formElement);
        while(elementvalue.indexOf("?")>=0){
			elementvalue = elementvalue.replace("?","`");
		}
		while(elementvalue.indexOf("\\")>=0){
			elementvalue = elementvalue.replace("\\","/");
		}
        var value = deltaLog.createElement("value");
        value.setAttribute("key", name);
        value.text = elementvalue;
        mapElement.appendChild(value);
    }
    rootElement.appendChild(mapElement);
    xml = deltaLog.xml;
    deltaLog = null;
    return xml;
}

//获得业务xml
function createYwXml(forms,names,bdtables,tables,ywid){

    var form = forms.elements;
    var size = form.length;
    var name = "";
    var formElement = null;
    var elementname = "";
    var elementvalue = "";
    var rootElement = null;
    var deltaLog = null;
    var xml = "<datas></datas>";
    var deltaLog = new ActiveXObject("Msxml2.DOMDocument.3.0");
    deltaLog.loadXML(xml);
    rootElement = deltaLog.documentElement;
    var mapElement = deltaLog.createElement("map");
    mapElement.setAttribute("key", ywid);
    for(var index = 0; index < size; index ++){
        formElement = form[index];
         //2008-12-02 LHT:过滤掉FIELDSET和legend标签
        var tagmc = formElement.tagName;        
        if((tagmc.toUpperCase()=="FIELDSET") ||(tagmc=="undefined")) continue;
        
        var comType = formElement.type.toUpperCase();
        if(comType=="BUTTON"){
        	continue;
        }
        name = getFormElementAtt(formElement, "name");
        if (isNameExist(name,names)==false){
            continue;
        }
        elementvalue = getElementValue(formElement);
        while(elementvalue.indexOf("?")>=0){
			elementvalue = elementvalue.replace("?","`");
		}
		while(elementvalue.indexOf("\\")>=0){
			elementvalue = elementvalue.replace("\\","/");
		}
        var value = deltaLog.createElement("value");
        value.setAttribute("key", name);
        value.text = elementvalue;
        mapElement.appendChild(value);
    }
    rootElement.appendChild(mapElement);
    for(var i=0;i<bdtables.length;i++){
    	var table1element = bdtables[i].getXmlOfUpdateModel();
    	rootElement.appendChild(table1element);
    }
    for(var i=0;i<tables.length;i++){
    	var table1element = tables[i].getXmlOfAllData();
    	rootElement.appendChild(table1element);
    }
    xml = deltaLog.xml;
    deltaLog = null;
    return xml;
}

//获得校验xml
function createJyYwXml(forms,names,bdtables,tables,ywid){
    var form = forms.elements;
    var size = form.length;
    var name = "";
    var formElement = null;
    var elementname = "";
    var elementvalue = "";
    var rootElement = null;
    var deltaLog = null;
    var xml = "<datas></datas>";
    var deltaLog = new ActiveXObject("Msxml2.DOMDocument.3.0");
    deltaLog.loadXML(xml);
    rootElement = deltaLog.documentElement;
    var mapElement = deltaLog.createElement("map");
    mapElement.setAttribute("key", ywid);
    for(var index = 0; index < size; index ++){
        formElement = form[index];
         //2008-12-02 LHT:过滤掉FIELDSET和legend标签
        var tagmc = formElement.tagName;        
        if((tagmc.toUpperCase()=="FIELDSET") ||(tagmc=="undefined")) continue;
        
        var comType = formElement.type.toUpperCase();
        if(comType=="BUTTON"){
        	continue;
        }
        name = getFormElementAtt(formElement, "name");
        if (isNameExist(name,names)==false){
            continue;
        }
        elementvalue = getElementValue(formElement);
        while(elementvalue.indexOf("?")>=0){
			elementvalue = elementvalue.replace("?","`");
		}
		while(elementvalue.indexOf("\\")>=0){
			elementvalue = elementvalue.replace("\\","/");
		}
        var value = deltaLog.createElement("value");
        value.setAttribute("key", name);
        value.text = elementvalue;
        mapElement.appendChild(value);
    }
    rootElement.appendChild(mapElement);
    for(var i=0;i<bdtables.length;i++){
    	var table1element = bdtables[i].getXmlOfAllData();
    	rootElement.appendChild(table1element);
    }
    for(var i=0;i<tables.length;i++){
    	var table1element = tables[i].getXmlOfAllData();
    	rootElement.appendChild(table1element);
    }
    xml = deltaLog.xml;
    deltaLog = null;
    return xml;
}

//获得xml文档
function getXmlFromString(str){
    if(window.DOMParser){  
		var p = new DOMParser();
		return p.parseFromString(str,"text/xml");  
	}else if(window.ActiveXObject){  
		var doc   =   new   ActiveXObject("Msxml2.DOMDocument");  
		doc.loadXML(str); 
		return doc;  
	}else{
		return false;  
	}
}

//根据表格选种行数据初始化form表单
function setValue(formName,form1,userKeys,userValues){
	var parent = window.dialogArguments;
	var map = parent.getRowValues();
	var keys;
	var keyLenth;
	if(userKeys){
		keys = userKeys;
		keyLenth = userKeys.length;
	}else{
		keys = parent.getKeys();
		keyLenth = keys.length - 1;
	}
	var str= "";
	for(var i=0;i<keyLenth;i++){
		var mapValue = map.get(keys[i]);
	    if(keys[i]=="xp_pre"){
	    
	    	if(form1!=null){
		    	if(mapValue!=null && mapValue!=""){
			    	form1.xp_pre.value = mapValue;
			    	form1.xp_preview.src = mapValue;
		    	}else{
			    	form1.xp_pre.value = "";
			    	form1.xp_preview.src = urlpath + "/images/none.jpg";
		    	}
	    	}
	    }else{
	        if(mapValue=="null"||typeof(mapValue)=="undefined"){
				mapValue = "\""+""+"\"";
	    	}else{
	    		mapValue = "\""+mapValue+"\"";
	    	}
	    	if(userValues){
	    		str = str+formName+"."+userValues[i]+".value="+mapValue+";";
	    	}else{
	    	   
	    	    str = str+formName+"."+keys[i]+".value="+mapValue+";";
	
				
			}
		}
	}
	eval(str);
	
}	

//弹出窗体
function openModalDialog(url, initParam, width,height){
   var windowheight = height;
   var windowwidth = width;
   if (windowheight == null ) windowheight = 720;
   if (windowwidth == null ) windowwidth = 900;
   if ( windowheight < 0 )
   {
      windowheight = "0";
   }
   retval = window.showModalDialog(url,
     initParam, "dialogHeight: "+windowheight+"px; dialogWidth: "+windowwidth+"px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");

   return retval;
}

/**
 * 定义ajax客户端调用信息
 */
var REMOTE_URL = "";
var REMOTE_METHOD = "";
var REMOTE_PARAM  = "";
var REMOTE_CALLBACK = null;
var HTTPXML_REQUEST = null;

var paction="";
var pparam="";

//用户使用的发送请求的公共方法
function remoteCall(url, method, param, callback){
  REMOTE_URL = url;
  paction = url;
  REMOTE_METHOD = method;
  REMOTE_PARAM = param;
  pparam = param;
  if(callback!=null){
  	REMOTE_CALLBACK = callback;
  }else{
  	REMOTE_CALLBACK = recall;
  }
  showLoadingDivRk();
  window.setTimeout("doRemoteCall()", 1);
}

//发送xmlhttp请求
function doRemoteCall(){
    REMOTE_METHOD = REMOTE_METHOD||"post";
    REMOTE_PARAM = REMOTE_PARAM||"";
    try{
         HTTPXML_REQUEST = new ActiveXObject("Microsoft.XMLHTTP");
         REMOTE_PARAM = encodeURI(REMOTE_PARAM);
         HTTPXML_REQUEST.onreadystatechange = remoteCallStateChanged;
         HTTPXML_REQUEST.open(REMOTE_METHOD, REMOTE_URL, true);
         HTTPXML_REQUEST.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
         HTTPXML_REQUEST.send(REMOTE_PARAM);
    }
    catch (e){alert(e);}
}

function saturn_praseXMl(str){
	//alert("start prase");
	//var str = "<list key=\"__ERROR_MESSAGE__\"><map key=\"0\"><value key=\"validateValue\"></value><value key=\"message\">姓名应至少由两个汉字组成、不能含有非法字符！</value><value key=\"exception\"></value></map><map key=\"1\"><value key=\"validateValue\"></value><value key=\"message\">姓名应至少由两个汉字组成、不能含有非法字符！</value><value key=\"exception\"></value></map></list>";
	var start = str.indexOf("<list");
	var end = str.indexOf("</list>");
	
	var xml = str.substring(start, end) + "</list>";
	var xmlDoc = getXmlFromString(xml);
	var message = "";
	var root = xmlDoc.documentElement;
	var map = root.getElementsByTagName("map"); 
	for(var i=0;i<map.length;i++){
		var values = map[i].getElementsByTagName("value");
		var value = "";
		if (values[0].firstChild) {
			value = values[0].firstChild.nodeValue;
		}
		var errorInfo = "";
		if (values[1].firstChild) {
			errorInfo = values[1].firstChild.nodeValue;
		}
		var msg = "<font color='red'>" + "第" + (i + 1) + "个错误：信息" + value + ", " + errorInfo + "</font><br>";
			message += msg;
	}
	message = message.substring(0,message.length-1);
	return message;
}

//回调函数
function remoteCallStateChanged(){
   if (HTTPXML_REQUEST.readyState == 4){
      var xml = HTTPXML_REQUEST.responseText;
      var doc = new ActiveXObject("Msxml2.DOMDocument.3.0");
      doc.loadXML(xml);
      var result = new Object();
      try{
      	result.success = doc.selectSingleNode("//datas/map/value[@key=\"success\"]").text == "true" ? true:false;
      	result.code = doc.selectSingleNode("//datas/map/value[@key=\"code\"]").text;
      	result.text = doc.selectSingleNode("//datas/map/value[@key=\"text\"]").text;
      	try{
      	result.ccictext = doc.selectSingleNode("//datas/map/value[@key=\"ccictext\"]").text;
      	}catch (e){}
      	result.isNewType = false;
      }catch (e){
      	result.success = false;
      	result.code = "custom";
      	result.text = "操作错误，请重试！";
      	if(xml){
      		result.isNewType = true;
      		result.newMessage = saturn_praseXMl(xml);
      	}
      }
      hideLoadingDivRk();
      HTTPXML_REQUEST = null;
      REMOTE_URL = "";
      REMOTE_METHOD = "";
      REMOTE_PARAM = "";
      if (REMOTE_CALLBACK != null) REMOTE_CALLBACK(result);
   }
}

//先是等待框
function showLoadingDivRk(){
   var div = document.getElementById("loadingdiv");
   if (div) div.removeNode(true);
   var sBG = '<div id="loadingdiv" style="position:absolute;top:0px;left:0px;width:100%;height:100%;background:url(' + urlpath + '/images/blank.gif)"><table border="1" bgcolor="white" id="loadingtable" bordercolor="#C0C0C0">\
   <tr>\
   <td align=right bordercolor=white>\
   <img border="0" src="' + urlpath + '/images/loadingsave.gif"></td>\
   <td aling=left bordercolor=white><font face="Arial,Helvetica" size="4"><b>正在提交请求，请稍候...</b></td>\
   </tr>\
   </table></div>';
   var oDiv = document.body.insertAdjacentHTML("beforeEnd", sBG);
   
   var divwidth = 0;
   var divheight = 0;

   divwidth = Math.max(document.body.scrollWidth, document.body.clientWidth) + "px";
   divheight = Math.max(document.body.scrollHeight, document.body.clientHeight)  + "px";
   document.getElementById("loadingdiv").style.width=divwidth;
   document.getElementById("loadingdiv").style.height=divheight;
   middleItRk('loadingtable');
 }

function middleItRk (_sId){
   var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
   var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
   var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
   document.getElementById(_sId)['style']['display'] = '';
   document.getElementById(_sId)['style']['position'] = "absolute";
   document.getElementById(_sId)['style']['left'] = (document.body.clientWidth / 2) - (document.getElementById(_sId).offsetWidth / 2);
   var sTop = -80 + (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
   document.getElementById(_sId)['style']['top'] = sTop > 0 ? sTop : (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
}

//隐藏显示框
function hideLoadingDivRk(){
   var div = document.getElementById("loadingdiv");
   if (div) div.removeNode(true);
 }
 
/*弹出警告框
  arg:敬告信息
  action:警告后调用的action
  param:警告后调用的action需要的参数
  func:警告后调用的action后调用的函数名
*/
function opendiaWarn(arg,action,param,func){
   var args = new Object();
   args.message="<br><font color=red>警告："+arg+"！</font><br><br>请选择下列操作：";
   args.defaultReturnValue = "ok";
   var rtn = showWarningDialog(args);
   if (rtn == "ok"){
       param = param.replace("&isWarning=true","&isWarning=false");
   	   remoteCall(action,"post",param,func);
   }
}

//显示警告对话框
function showWarningDialog(dialogArgs){
    var retval = openModalDialog(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/warningDialog.jsp",dialogArgs,550,220);
    return retval;
}

//显示错误对话框
function showErrorDialog(dialogArgs){
    var retval = openModalDialog(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/errorDialog.jsp",dialogArgs,550,220);
    return retval;
}

//弹出警错误框
function openErrorDialog(arg){
    var args = new Object();
    args.message="<font color=red>数据保存失败！</font><br>" + arg ;
    showErrorDialog(args);
    args = null;
}

//用户的回调函数
function recall(res){


	//if (HTTPXML_REQUEST.readyState == 4){
	 //   	 var xml = HTTPXML_REQUEST.responseText; 
	 //   	 
	 //   	 alert("xml:::"+xml);
	 //  }
	   
	   
	   
	if(res.isNewType == false) {
	  	if(res.success){
	  		if(res.code=="warning"){
	  			opendiaWarn(res.text,paction,pparam,recall);
	  		}else{
	  			openModalDialog(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/print.jsp?hh="+res.text,null,700,400);
	  			window.open(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/success.jsp","_self");
	  		}
	  	}else{
	  		if(res.code=="error")
	  			openErrorDialog(res.text);
	  	}
	} else {
		openErrorDialog(res.newMessage);
	}
}

function jsRedirect(url){ 
	var pr; 
	for(pr=window;;pr=window.parent){ 
		if(pr.parent==null);
		else{
			pr.location.href=url;break;} 
	} 
} 

 //选择照片
function uploadBlob(from){
	var retval = window.showModalDialog(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/post.jsp",window, "dialogHeight: 300px; dialogWidth: 440px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");
	if(retval){
		from.xpxlh.value = retval[0];
		from.xp_preview.src = retval[1];
		from.xp_pre.value = retval[1]; 	
	}
}

//清除照片
function deleteBlob(from){
    id = from.xpxlh.value;
    if(id!=null && id!=""){
		var action = urlpath+"/rk1305.baseplugin::/czrkCommonModule/action/DeleteXpFromTemp_bolbById.action";
    	var parm = "id=" + id;
    	remoteCall(action,"post",parm,deleteBlobRecall);
    }
	from.xpxlh.value = "";
	from.xp_pre.value = "";
	from.xp_preview.src = urlpath+"/images/none.jpg";

}

//清除照片的回调函数
function deleteBlobRecall(res){
}

/******************************************************************************
 *      功能：Map对象
 *      作者：rkxt
 *      时间：2007-07-24
 *      修改：
 *
 *****************************************************************************/
 function Pair(key, value) {
    this.key = key == null ? "" : key;
    this.value = value;

    this.toString = function() {
        return this.key + "=" + this.value;
    };
}
 
function Map(pairs) {
    this.pairs = pairs || new Array();
    this.afterSet = null;
    this.afterRemove = null;

    this.putValue = function(pair) {
        this.putPair(pair);
    }

    this.makeMap = function(key, value)
    {
        for(var i=0;i<key.length;i++)
        {
            if (value == null)
            {
                this.put(key[i], "");
            }
            else
            {
                this.put(key[i], value[i]);
            }
        }
    }

    this.putPair = function(pair) {
        this.pairs[this.pairs.length] = pair;
        if (this.afterSet != null) {
            this.afterSet(pair, this);
        }
    }

    this.put = function(key, value)
    {
        this.putValue(new Pair(key, value));
    }

    this.putAll = function(map) {
        if (!(map instanceof Map)) {
            return;
        }
        var entries = map.getEntries();
        for (var i = 0; i < entries.length; i++) {
            this.putPair(entries[i]);
        }
    }

    this.size = function() {
        return this.pairs.length;
    }

    this.get = function(key) {
        for (var i = 0; i < this.pairs.length; i++) {
            var pair = this.pairs[i];
            if (pair.key == key) {
                return pair.value;
            }
        }
        return null;
    }

    this.getKeys = function() {
        var ret = new Array();
        for (var i = 0; i < this.pairs.length; i++) {
            ret[ret.length] = this.pairs[i].key;
        }
        return ret;
    }

    this.getValues = function() {
        var ret = new Array();
        for (var i = 0; i < this.pairs.length; i++) {
            ret[ret.length] = this.pairs[i].value;
        }
        return ret;
    }

    this.getEntries = function() {
        return this.getPairs();
    }

    this.getPairs = function() {
        var ret = new Array();
        for (var i = 0; i < this.pairs.length; i++) {
            ret[ret.length] = this.pairs[i];
        }
        return ret;
    }

    this.update = function (key, value) {
        var retval = false;
        for (var i = 0; i < this.pairs.length; i++) {
            var pair = this.pairs[i];
            if (pair.key == key) {
                this.pairs.splice(i, 1);
                this.pairs.splice(i, 0, new Pair(key, value));
                retval = true;
                break;
            }
        }
        return retval;
    }

    this.remove = function (key) {
        for (var i = 0; i < this.pairs.length; i++) {
            var pair = this.pairs[i];
            if (pair.key == key) {
                this.pairs.splice(i, 1);
                if (this.afterRemove != null) {
                    this.afterRemove(pair, this);
                }
                return pair;
            }
        }
        return null;
    }

    this.clear = function (key) {
        var ret = this.pairs;
        for (var i = 0; i < ret.length; i++) {
            this.remove(ret[i].key);
        }
        return ret;
    }

}

/******************************************************************************
 *      功能：回车事件处理
 *      作者：rkxt
 *      时间：2007-07-24
 *      修改：
 *
 *****************************************************************************/
var F1 = 112; var F2 = 113;  var F3 = 114;   var F4 = 115;
var F5 = 116; var F6 = 117;  var F7 = 118;   var F8 = 119;
var F9 = 120; var F10 = 121; var F11 = 122;  var F12 = 123;
var ESC = 27; 

var keyPress = new KeyPress(document);
var keyflag = true;

//回车信息值对
function EnterKeyPair(key, id, fun,enabled)
{
    this.key = key == null ? 0 : key;
    this.id = id == null ? "" : id;
    this.fun = fun == null ? "" : fun;
    this.enabled = enabled == null ? true:false;
}

//按键对象
function KeyPress(doc)
{
    this.doc = doc;
    this.initflag = false;
    this.enterQueue = new Map();
    this.keyArray = new Array();
}

// 清除资源
function KeyPress.prototype.clearAll(){
    var formPair = this.enterQueue.getPairs();
    var size = formPair.length;
    for(var index = 0; index < size; index++)
    {
        var comsPair = formPair[index];
        var tmpValue = comsPair.value;
        var length = tmpValue.length;
        for(var indexy = 0; indexy < length; indexy)
        {
            var tmpPair = this.tmpValue[index];
            tmpPair.key = null;
            tmpPair.id = null;
            tmpPair = null;
        }
        tmpValue.splice(0, size);
        comsPair.value = null;
        comsPair.key = null;
    }
    formPair = null;
}

// 增加控件列表
function KeyPress.prototype.addComponent(tabAtt, component)
{
    var insert = false;
    var formPair = this.enterQueue.get(component.form.name);
    if (formPair == null)
    {
        formPair = new Array();
        this.enterQueue.put(component.form.name, formPair);
    }
    var size = formPair.length;
    for(var index = 0; index < size; index++)
    {
        var tmpPair = formPair[index];
        if (Number(tmpPair.key) > Number(tabAtt) )
        {
            formPair.splice(index, 0, new EnterKeyPair(tabAtt, component.id));
            insert = true;
            break;
        }
    }
    if (insert==false)
    {
        formPair[size] = new EnterKeyPair(tabAtt, component.id);
    }
    tmpPair = null;
}

// 提取下一焦点位置
function KeyPress.prototype.getNextComponent(component, flag)
{
    if (this.initflag == false)
    {
        this.initEnterQueue();
    }
    if(typeof component.type == "undefined")
        return;
    var formname = component.form.name;
    var formPair = this.enterQueue.get(formname);
    var componentID = component.id;
    var size = 0;
    if(formPair){
    	size = formPair.length;
    }
    if (size > 0)
    {
        var componentNextID = null;
        for(var index = 0; index < size; index++)
        {
            var tmpPair = formPair[index];
            if (tmpPair.id == componentID )
            {
                if (index == (size - 1))
                {
                    componentNextID = formPair[0].id;
                }
                else
                {
                    componentNextID = formPair[index + 1].id;
                }
                break;
            }
        }
        var nextComponent = null;
        if(componentNextID!=null&&componentNextID!="")
        	nextComponent = this.doc.getElementById(componentNextID);
        if (nextComponent != null && typeof nextComponent != "undefined")
        {
            if (typeof(inputDictItemBox) != "undefined" && inputDictItemBox != null)
            {
                    if (typeof(inputDictItemBox.INPUT_DICT_VALUEOBJ) != "undefined" && inputDictItemBox.INPUT_DICT_VALUEOBJ != null){
                        if (inputDictItemBox.INPUT_DICT_GLOBALDIV.style.visibility == "visible"){
                            var selNum = inputDictItemBox.getSelectedSpanNum(inputDictItemBox.INPUT_DICT_GLOBALDIV);
                            var selSpan = setSelectedSpan(inputDictItemBox.INPUT_DICT_GLOBALDIV, selNum);
                            if (selSpan && flag==false)
                            {
                                _selectResult(selSpan);
                            } else if (inputDictItemBox.isFocusInput == true || flag == true) {
                                inputDictItemBox.isFocusInput == false;
                                if (!flag){
                                    inputDictItemBox.isClose = true;
                                } else {
                                    return;
                                }
                            } else {
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.focus();
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.select()
                            }
                        }
                    }
                    if (inputDictItemBox.isClose == false)
                    {
                        if (typeof(inputDictItemBox.INPUT_DICT_VALUEOBJ) != "undefined" &&
                            inputDictItemBox.INPUT_DICT_VALUEOBJ != null)
                        {
                            if(inputDictItemBox.INPUT_DICT_VALUEOBJ.value!="" && inputDictItemBox.INPUT_DICT_CODEOBJ.value==""){
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.focus();
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.select();
                                return;
                            }
                        }
                    }
            }
            nextComponent.focus();
            nextComponent.select();
        }
        nextComponent = null;
        tmpPair = null;
    }
}

// 提取上一个焦点位置
function KeyPress.prototype.getPreComponent(component,flag)
{
    if (this.initflag == false)
    {
        this.initEnterQueue();
    }
    if (typeof component.type == "undefined")
        return;
    var formname = component.form.name;
    var formPair = this.enterQueue.get(formname);
    var componentID = component.id;
    var size = 0;
    if(formPair){
    	size = formPair.length;
    }
    if (size > 0)
    {
        var componentNextID = null;
        for(var index = 0; index < size; index++)
        {
            var tmpPair =formPair[index];
            if (tmpPair.id == componentID )
            {
                if (index == 0)
                {
                    componentNextID = formPair[size - 1].id;
                }
                else
                {
                    componentNextID = formPair[index - 1].id;
                }
                break;
            }
        }
        
        var nextComponent = null;
        if(componentNextID!=null&&componentNextID!="")
        	nextComponent = this.doc.getElementById(componentNextID);
        	
        if (nextComponent != null)
        {
            if (typeof(inputDictItemBox) != "undefined" && inputDictItemBox != null)
            {
                    if (typeof(inputDictItemBox.INPUT_DICT_VALUEOBJ) != "undefined" && inputDictItemBox.INPUT_DICT_VALUEOBJ != null){
                        if (inputDictItemBox.INPUT_DICT_GLOBALDIV.style.visibility == "visible"){
                            var selNum = inputDictItemBox.getSelectedSpanNum(inputDictItemBox.INPUT_DICT_GLOBALDIV);
                            var selSpan = setSelectedSpan(inputDictItemBox.INPUT_DICT_GLOBALDIV, selNum);
                            if (selSpan && flag==false)
                            {
                                _selectResult(selSpan);
                            } else if (inputDictItemBox.isFocusInput == true || flag == true) {
                                inputDictItemBox.isFocusInput == false;
                                if (!flag){
                                    inputDictItemBox.isClose = true;
                                } else {
                                    return;
                                }
                            } else {
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.focus();
                                inputDictItemBox.INPUT_DICT_VALUEOBJ.select()
                            }
                        }
                    }
                    if (inputDictItemBox.isClose == false)
                    {
                        if (typeof(inputDictItemBox.INPUT_DICT_VALUEOBJ) != "undefined" &&
                            inputDictItemBox.INPUT_DICT_VALUEOBJ != null)
                        {
                            inputDictItemBox.INPUT_DICT_VALUEOBJ.focus();
                            inputDictItemBox.INPUT_DICT_VALUEOBJ.select();
                            return;
                        }
                    }
            }
            nextComponent.focus();
            nextComponent.select();
        }
        nextComponent = null;
        tmpPair = null;
    }
}

function KeyPress.prototype.initEnterQueue()
{
    if (this.initflag)
        return;
    var formList = this.doc.forms;
    var size = formList.length;
    for(var index = 0; index < size; index++)
    {
        var tmpForm = formList[index];
        var length = tmpForm.elements.length;
        for(var indexy = 0; indexy < length; indexy ++)
        {
	        var comType="";
	        if(tmpForm.elements[indexy].type=="undefined"){
	            comType = tmpForm.elements[indexy].type.toUpperCase();
	         }
            var tabAtt = tmpForm.elements[indexy].getAttribute("isenter");
            if (tabAtt == "undefined" || tabAtt == null || tabAtt == "")
                continue;

            if (comType == "TEXT" || comType == "BUTTON" || comType == "SELECT-ONE"
                || comType == "CHECKBOX" || comType == "RADIO")
            {
                this.addComponent(tabAtt, tmpForm.elements[indexy]);
            }
        }
    }
    tmpForm = null;
    formList = null;
    this.initflag = true;
}
//禁用快捷键
function KeyPress.prototype.setEnabledKey(code, flag)
{
    var setFlag = false
    if (flag)
        setFlag = flag;

    var size = this.keyArray.length;

    for(var index =0; index < size; index++)
    {
        var tmpEnterKeyPair = this.keyArray[index];
        if (tmpEnterKeyPair.key == code)
        {
            tmpEnterKeyPair.enabled = flag;
            break;
        }
    }
}

//按键事件处理
function KeyPress.prototype.OnKeyDown()
{
    var destcomponent = event.srcElement;
    var code = window.event.keyCode;
    var size = this.keyArray.length;
    for(var index =0; index < size; index++)
    {
        var tmpEnterKeyPair = this.keyArray[index];
        if (tmpEnterKeyPair.key == code)
        {
            if (tmpEnterKeyPair.enabled == true)
            {
                eval("window.setTimeout(\"" + tmpEnterKeyPair.fun + "\", 1);");
                window.event.keyCode    = 0;
                window.event.cancelBubble = true;
                window.event.returnValue= false;
            }
            return;
        }
    }
    var doFlag = false;
    if (typeof DICT_DIVNAME != "undefined")
    {
        doFlag = getDivVisible();
    }
    if (!doFlag)
    {
        if (code == 40 && keyflag)
        {
            this.getNextComponent(destcomponent,true);
            window.event.cancelBubble = false;
            window.event.returnValue = false;
        }
        if (code == 38 && keyflag)
        {
            this.getPreComponent(destcomponent,true);
            window.event.cancelBubble = false;
            window.event.returnValue = false;
        }
    }
    if (code == 13 && keyflag)
    {
        this.getNextComponent(destcomponent,false);
        window.event.cancelBubble = false;
        window.event.returnValue = false;
    }
    return true;
}

//按键事件处理
function KeyPress.prototype.registerKeyFunction(key, functionname)
{
    this.keyArray[this.keyArray.length] = new EnterKeyPair(key, "1", functionname);
}

function KeyPress.prototype.unRegisterSetKeyFunction(key)
{
    var size = this.keyArray.lenght;
    for(var index =0; index < size; index++)
    {
        var tmpEnterKeyPair = this.keyArray[index];
        if (tmpEnterKeyPair.key == key)
        {
            this.keyArray.splice(index, 1);
            break;
        }
    }
}
function KeyPress.prototype.unRegisterAll()
{
    this.keyArray.splice(0, this.keyArray.length);
}

//创建字典url dictname:字典名 maxItems:显示条数 dynamicConditon:动态条件
function createDictUrl(dictname,maxItems,dynamicConditon){
//	var action = urlpath+"/cn.com.cchongda.saturn.rkxt::/commonModule/action/QueryDictInfoFromDataBaseAction.action";
//修改成邢台系统
	var action = urlpath+"/rk1305.baseplugin::/czrkCommonModule/action/QueryDictInfoFromDataBaseAction.action";
	var url = "";
	if(dictname=="custom"){
		url = action+"?"+"id="+dictname+"&startIndex=0&maxItems="+maxItems+"&dictTable="+dictname+"&dynamicConditon="+dynamicConditon;
	}else{
		url = action+"?"+"id="+dictname+"&startIndex=0&maxItems="+maxItems+"&dictTable=zh_dictvalue"+"&dynamicConditon="+dynamicConditon;
	}
	return url;
}
//取当前系统时间YYYYMMDD格式
function getCurrentDate(){
    var curDate = new Date;
    var month = curDate.getMonth()+1 ; 
    var date = curDate.getDate() ;
    if(month<10){
      month="0"+month;
    }
    if(date<10){
      date = "0"+date
    }
    return curDate.getFullYear()+""+month+""+date;
  }
  
//clj 2008-07-08 add
function showSuccessPage(res){
  if(res.success){
    window.open(urlpath+"/rk1305.baseplugin/czrkCommonModule/page/success.jsp","_self");
  }
 }


//通过家庭关系获得相应的数据 LHT 2008-09-12
	function getDataByYhzgx(yhzgx,hh,csdjForm){	
		
		var fqxm=csdjForm.fqxm.value;
		var mqxm=csdjForm.mqxm.value;
		var jhryxm=csdjForm.jhryxm.value;
		
	
		
		
		if(fqxm!=""||mqxm!=""||jhryxm!="") return;
		
		if((yhzgx>=20) && (yhzgx<= 39)&& (yhzgx!= 27 && yhzgx !=28&&yhzgx!=37 && yhzgx!=38)){
			
			var action=urlpath+"/rk1305.baseplugin::/czrkCommonModule/action/GetDataByYhzgx.action"
			 var param = "hh="+hh;
			//var param = "hh=002981297";			 
			 try{
		         xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
		       
		         xmlhttp_request.open("post", action, false);
		         xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		         xmlhttp_request.send(param);
		         var returnValue=xmlhttp_request.responseText;
		         setFormValueByHh(returnValue,csdjForm);
	      	 }catch (e){alert(e);}
			 
		}
		/**else{
			csdjForm.jgssx.value = '';
			csdjForm.jgssx_dict.value = '';
			csdjForm.csdxz.value = '';
			csdjForm.jhryhm.value = '';
			csdjForm.mqxm.value = '';
			csdjForm.jhryxm.value = '';
			csdjForm.fqxm.value = '';
			csdjForm.jhrexm.value = '';
			csdjForm.jhrehm.value = '';
			csdjForm.jhregx.value = '';
			csdjForm.jhregx_dict.value = '';
			csdjForm.csdssx.value = '';
			csdjForm.csdssx_dict.value = '';
			csdjForm.jhrygx.value = '';
			csdjForm.jhrygx_dict.value = '';
			csdjForm.fqhm.value = '';
			csdjForm.mqhm.value = '';
		
		}	**/	
	}
	//定义函数完成监护人,父亲,母亲籍贯等数据赋值
  	function setFormValueByHh(returnValue,csdjForm){  		
		var doc = new ActiveXObject("Msxml2.DOMDocument.3.0");
		doc.loadXML(returnValue);
		
		csdjForm.jgssx.value = doc.selectSingleNode("//datas/map/value[@key=\"jgssx\"]").text;
		csdjForm.jgssx_dict.value = doc.selectSingleNode("//datas/map/value[@key=\"jgssx_dict\"]").text;
		csdjForm.csdxz.value = doc.selectSingleNode("//datas/map/value[@key=\"csdxz\"]").text;
		csdjForm.jhryhm.value = doc.selectSingleNode("//datas/map/value[@key=\"jhryhm\"]").text;
		csdjForm.mqxm.value = doc.selectSingleNode("//datas/map/value[@key=\"mqxm\"]").text;
		csdjForm.jhryxm.value = doc.selectSingleNode("//datas/map/value[@key=\"jhryxm\"]").text;
		csdjForm.fqxm.value = doc.selectSingleNode("//datas/map/value[@key=\"fqxm\"]").text;
		csdjForm.jhrexm.value = doc.selectSingleNode("//datas/map/value[@key=\"jhrexm\"]").text;
		csdjForm.jhrehm.value = doc.selectSingleNode("//datas/map/value[@key=\"jhrehm\"]").text;
		csdjForm.jhregx.value = doc.selectSingleNode("//datas/map/value[@key=\"jhregx\"]").text;
		csdjForm.jhregx_dict.value = doc.selectSingleNode("//datas/map/value[@key=\"jhregx_dict\"]").text;
		csdjForm.csdssx.value = doc.selectSingleNode("//datas/map/value[@key=\"csdssx\"]").text;
		csdjForm.csdssx_dict.value = doc.selectSingleNode("//datas/map/value[@key=\"csdssx_dict\"]").text;
		csdjForm.jhrygx.value = doc.selectSingleNode("//datas/map/value[@key=\"jhrygx\"]").text;
		csdjForm.jhrygx_dict.value = doc.selectSingleNode("//datas/map/value[@key=\"jhrygx_dict\"]").text;
		csdjForm.fqhm.value = doc.selectSingleNode("//datas/map/value[@key=\"fqhm\"]").text;
		csdjForm.mqhm.value = doc.selectSingleNode("//datas/map/value[@key=\"mqhm\"]").text;
		
		       	 
  	}
  
    //判断是否存在照片，有返回true
    function isHavePic(xpObj){
	    var size = Math.round(xpObj.fileSize*100/1024)/100;
	    var xpsrc = xpObj.src;
	    var noneXp = urlpath+"/images/none.jpg";
	    if(size==0){
	    	alert("请选择照片！");
	    	return false;
	    }else if(xpsrc.indexOf(noneXp)>0){
	   		alert("请选择照片！");
	    	return false;
	    }else{
	    	return true;
	    }
	}
	
	//汉字转码
   function UTF8UrlEncode(input){
		var output = "";
		var currentChar = '';
		
		for(var counter = 0; counter < input.length; counter++){
			currentChar = input.charCodeAt(counter);
			
			if((48 <= currentChar) && (currentChar <= 57))
				output = output + input.charAt(counter);
			else if((65 <= currentChar) && (currentChar <= 90))
				output = output + input.charAt(counter);
			else if((97 <= currentChar) && (currentChar <= 122))
				output = output + input.charAt(counter);
			else
				output =  output + UTF8UrlEncodeChar(currentChar);
		}
		return output;
	}
	
	function UTF8UrlEncodeChar(input){
		if(input <= 0x7F) return "%" + input.toString(16);		
		var leadByte = 0xFF80; var hexString = ""; var leadByteSpace = 5;
		while(input > (Math.pow(2, leadByteSpace + 1) - 1)){
			hexString = "%" + ((input & 0x3F) | 0x80).toString(16) + hexString;
			leadByte = (leadByte >> 1);
			leadByteSpace--;
			input = input >> 6;
		}
		return ("%" + (input | (leadByte & 0xFF)).toString(16) + hexString).toUpperCase();
	}
	
	/**************为Form表单赋值****************************************************************************/
	var NOPREFIX = "NoPrefix";
	var SATURNDATANAME = "saturnDataName";
	var SETVALUEFLAG = "clearflag";
	var FRMPREFIX = "__";
	var FLAGVALUE = "0";
	
	function setFrmValueByKeys(frmName,xmlDoc){
		var keysMap = getKeysFromFrm(frmName);
		var valuesMap = getValueMapFromXmlData(xmlDoc);
		setValueByKeys(keysMap,valuesMap,frmName);
	}
	
	function setValueByKeys(keysMap,valuesMap,frmName){
		if (keysMap && valuesMap && frmName){
			var prefixArray = keysMap.getKeys();
			var prefixArrayLength = prefixArray.length;	
			for (prefixIndex = 0; prefixIndex < prefixArrayLength;prefixIndex++){
				var prefixKey = prefixArray[prefixIndex];
				var keysArray = keysMap.get(prefixKey);
				if (prefixKey == NOPREFIX){
					setFrmControlValueByKeys(keysArray,valuesMap,frmName);		
				}else{			
					if (prefixKey == valuesMap.get(SATURNDATANAME)){				
						setFrmControlValueByKeys(keysArray,valuesMap,frmName,prefixKey);	
					}
				}	
			}	
		}	
	}
	
	function setFrmControlValueByKeys(keysArray,valuesMap,frmName,prefixKey){
		if (keysArray && valuesMap && frmName){
			var str = "";
			var keysArrayLength = keysArray.length;
			if (keysArray.length == 0 || valuesMap.getKeys().length == 0) return;
			for(var i=0;i<keysArrayLength;i++){
				var value = valuesMap.get(keysArray[i]);
			    if(value=="null"||typeof(value)=="undefined"){
					value = "\""+""+"\"";
			    }else{
			    	value = "\""+value+"\"";
			    }
			    if (value != "\"\""){
			    	if (prefixKey){
			    		str = str+frmName+"."+prefixKey + FRMPREFIX+ keysArray[i]+".value="+value+";";
			    	}else{
			    		str = str+frmName+"."+keysArray[i]+".value="+value+";";
			    	}			    	
			    }
			}
			eval(str);	
		}	
	}
	
	
	function getPrefixAndKeyValue(keyWithPrefix){
		var result = new Array();
		if (keyWithPrefix){
			if (keyWithPrefix.indexOf(FRMPREFIX) >0){
				var prefix = keyWithPrefix.substr(0,keyWithPrefix.indexOf(FRMPREFIX));
				result[0]= prefix;
				var key = keyWithPrefix.substr(keyWithPrefix.indexOf(FRMPREFIX)+2,keyWithPrefix.length);
				result[1] = key;			
			}else{
				result[0]= NOPREFIX;	
				result[1] = keyWithPrefix;	
			}
		}
		return result;
	}
	
	
	function getValueMapFromXmlData(xmlDoc){
		if (!xmlDoc){
			return;
		}
		var map = new HashMap();
	    var root = xmlDoc.documentElement;
	    var firstChildNode = root.childNodes[0];
	    if (!firstChildNode)return;
	    map.put(SATURNDATANAME,firstChildNode.attributes[0].value);
		var values = firstChildNode.childNodes;
	    for(var i=0;i<values.length;i++){
	       if(values[i].getAttribute("key")!=null && values[i].getAttribute("key")!=""){
	          if(values[i].firstChild){
	             map.put(values[i].getAttribute("key"),trim(values[i].firstChild.nodeValue));
	           }else{
	            	 map.put(values[i].getAttribute("key"),"");
	            }
	        }
	    }
	    return map;
	}
	function getKeysFromFrm(frmName){
		var frm = document.getElementById(frmName);
		if (!frm){
			return;
		}
		var fmLength = frm.length;
		var keyMap = new HashMap();	
		for(var index = 0; index < fmLength; index ++){
	        var child = frm(index);
	        var tagmc = child.tagName;        
	        if((tagmc.toUpperCase()=="FIELDSET") ||(tagmc=="undefined")) continue;        
	        var comType = child.type.toUpperCase();
	        if(comType != "TEXT" && comType != "HIDDEN"){
	        	continue;
	        }
	        if (child.getAttribute(SETVALUEFLAG) != FLAGVALUE) continue;
	        var comName = getFormElementAtt(child,"name");
	        setKeyMap(keyMap,comName);
		}
		return keyMap;
	}
	
	function setKeyMap(keyMap,tagName){
		if (!tagName || tagName == "") return;
		var prefixAndKeyArray = getPrefixAndKeyValue(tagName);	
		var prefix = prefixAndKeyArray[0];
		var keyName = prefixAndKeyArray[1];
		var keyNameArray = keyMap.get(prefix);	
		if(keyNameArray == "null" || typeof(keyNameArray)=="undefined"){
			keyNameArray = new Array();
			keyMap.put(prefix,keyNameArray);				
	    }
	    keyNameArray.push(keyName);    
	}
	
	   
	
	
	
	
	
	
	
	
	
	
 
 